package com.aaa.service.impl;

import com.aaa.dao.Test_plan_sdsDao;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_sdsService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class Test_plan_sdsServiceImpl implements Test_plan_sdsService {

    @Autowired
    private Test_plan_sdsDao plan_sdsDao;


    /**
    * @Author: WTH
    * @Description: 查询,分页，计算总条数
    * @Date:2022-07-03 18:02
    * @Params:
    */
    @Override
    public Page<Test_plan> selectSdsPlan(Test_plan plan_sds) {
        Page<Object> objects = PageHelper.startPage(plan_sds.getPage(), plan_sds.getLimit());
        List<Test_plan> test_plans = plan_sdsDao.selectSdsPlan(plan_sds);
        Page page= (Page) test_plans;
        return page;
    }

    /**
    * @Author: WTH
    * @Description: 新增,生成随机六位数
    * @Date:2022-07-03 18:03
    * @Params:
    */
    @Override
    public Enum01 addSdsPlan(Test_plan plan_sds) {
        Random six=new Random();
        String results="";
        for(int a=0;a<6;a++){
            results=results+six.nextInt(10);
        }
        Integer result=Integer.parseInt(results);
        plan_sds.setTest_code(result);
        int i = plan_sdsDao.addSdsPlan(plan_sds);
        if(i>0){
            return Enum01.SUCCESS;
        }else{
            return Enum01.FAIL;
        }
    }

    /**
     * @Author: WTH
     * @Description: 删除
     * @Date:2022-07-02 16:41
     * @Params:
     */
    @Override
    public boolean deleteSdsPlan(String id) {
        int i = plan_sdsDao.deleteSdsPlan(id);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-03 18:05
    * @Params:
    */
    @Override
    public Enum01 updateSdsPlan(Test_plan plan_sds) {
        int i = plan_sdsDao.updateSdsPlan(plan_sds);
        if(i>0){
            return Enum01.SUCCESS;
        }else{
            return Enum01.FAIL;
        }
    }

    /**
    * @Author: WTH
    * @Description: 根据邀请码查询
    * @Date:2022-07-07 15:49
    * @Params:
    */
    @Override
    public Test_plan selectByCode(Integer test_code) {
        Test_plan test_plan = plan_sdsDao.selectByCode(test_code);
        return test_plan;
    }

}
